<template>
  <div>自助挂号 <br>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="true" label-width="68px">
      <el-form-item label="科室" prop="depId">
        <el-select v-model="queryParams.depId" placeholder="请选择科室">
          <el-option v-for="item in depList" :key="item.deptId" :label="item.deptName" :value="item.deptId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="挂号日期" prop="scheduleDate">
        <el-date-picker clearable v-model="queryParams.scheduleDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择挂号日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="上午，下午" prop="scheduleTime">
        <el-select v-model="queryParams.scheduleTime" placeholder="请选择上午，下午" clearable>
          <el-option label="上午" value="上午"></el-option>
          <el-option label="下午" value="下午"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="scheduleList">
      <el-table-column label="科室名称" align="center" prop="depName" />
      <el-table-column label="排班日期" align="center" prop="scheduleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.scheduleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上午，下午" align="center" prop="scheduleTime"></el-table-column>
      <el-table-column label="医生姓名" align="center" prop="userName" />
      <el-table-column label="医生头像" align="center" prop="avatar" />
      <el-table-column label="接诊人数" align="center" prop="scheduleNum" />
      <el-table-column label="剩余名额" align="center" prop="0" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="$message.success('挂号成功')">挂号</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>

import { listSchedule } from "@/api/reghos-serv/schedule";
import { listDept } from "@/api/system/dept";



export default {
  data() {
    return {
      total: 0,
      loading: false,
      depList: [],
      scheduleList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        depId: undefined,
        scheduleDate: undefined,
        scheduleTime: undefined,
      },
    };
  },
  methods: {
    getList() {
      this.loading = true;
      listSchedule(this.queryParams).then(response => {
        this.scheduleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.scheduleList = [];
    },
    queryDepList() {
      listDept().then((result) => {
        this.depList = result.data;
      });
    },
  },
  created() {
    this.queryDepList();
  }
};
</script>